package com.gshrms.org.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gshrms.common.exception.ServiceException;
import com.gshrms.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.gshrms.org.mapper.OrgRoleMapper;
import com.gshrms.org.domain.OrgRole;
import com.gshrms.org.service.IOrgRoleService;

/**
 * 组织角色Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-28
 */
@Service
public class OrgRoleServiceImpl extends ServiceImpl<OrgRoleMapper,OrgRole> implements IOrgRoleService
{
    @Autowired
    private OrgRoleMapper orgRoleMapper;

    /**
     * 查询组织角色
     * 
     * @param roleId 组织角色主键
     * @return 组织角色
     */
    @Override
    public OrgRole selectOrgRoleByRoleId(Long roleId)
    {
        return orgRoleMapper.selectOrgRoleByRoleId(roleId);
    }

    /**
     * 查询组织角色列表
     * 
     * @param orgRole 组织角色
     * @return 组织角色
     */
    @Override
    public List<OrgRole> selectOrgRoleList(OrgRole orgRole)
    {
        return orgRoleMapper.selectOrgRoleList(orgRole);
    }

    /**
     * 新增组织角色
     * 
     * @param orgRole 组织角色
     * @return 结果
     */
    @Override
    public int insertOrgRole(OrgRole orgRole)
    {
        orgRole.setCreateTime(DateUtils.getNowDate());
        return orgRoleMapper.insertOrgRole(orgRole);
    }

    /**
     * 修改组织角色
     * 
     * @param orgRole 组织角色
     * @return 结果
     */
    @Override
    public int updateOrgRole(OrgRole orgRole)
    {
        if(orgRole.getRoleId() < 100){
            throw new ServiceException("内置组织角色无法修改");
        }

        orgRole.setUpdateTime(DateUtils.getNowDate());
        return orgRoleMapper.updateOrgRole(orgRole);
    }

    /**
     * 批量删除组织角色
     * 
     * @param roleIds 需要删除的组织角色主键
     * @return 结果
     */
    @Override
    public int deleteOrgRoleByRoleIds(Long[] roleIds)
    {
        for(Long roleId : roleIds){
            if(roleId < 100){
                throw new ServiceException("内置组织不允许被删除");
            }
        }

        return orgRoleMapper.deleteOrgRoleByRoleIds(roleIds);
    }

    /**
     * 删除组织角色信息
     * 
     * @param roleId 组织角色主键
     * @return 结果
     */
    @Override
    public int deleteOrgRoleByRoleId(Long roleId)
    {
        if(roleId < 100){
            throw new ServiceException("内置组织不允许被删除");
        }

        return orgRoleMapper.deleteOrgRoleByRoleId(roleId);
    }
}
